package com.sz.youban.controller.credit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sz.youban.controller.base.BaseController;
import com.sz.youban.dt.entity.result.ResultData;
import com.sz.youban.dt.entity.result.ResultDataEnum;
import com.sz.youban.dt.entity.result.ResultModel;
import com.sz.youban.dt.interfs.credit.IDtJuXinLiService;
import com.sz.youban.dt.model.MiguanReportRequest;
import com.sz.youban.dt.model.MsgException;
import com.sz.youban.dt.service.utils.JuxinliUtil;

/**
 * Created by liyang on 2017/6/27.
 */
@RestController
@RequestMapping("/credit")
public class JuxinliController extends BaseController {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IDtJuXinLiService juXinLiService;

    /**
     * 查询蜜罐报告接口
     */
    @PostMapping(value="miguanReport",consumes="application/json")
    public ResultModel miguanReport(@RequestBody MiguanReportRequest miguanReportRequest){

        log.info("----- miguanReport 接口请求参数 -----{}" , miguanReportRequest.toString());

        //----------1，请求参数校验----------
        if( !JuxinliUtil.checkMiguanReportParam(miguanReportRequest) ){
            log.info("----------miguanReport，必要参数不足");
            return success(ResultDataEnum.PARAMS_ERROR);
        }

        //----------2，请求service，对征蜜罐报告进行查询存储操作----------
        ResultData resultData = new ResultData();
        try {
            juXinLiService.saveCreditReport(miguanReportRequest.getName(), miguanReportRequest.getIdCard(), miguanReportRequest.getPhone());
        } catch (MsgException e) {
            resultData.setCode(e.getCode());  //暂定00000表示失败
            resultData.setMsg(e.getMsg());
            return success(resultData);
        }catch (Exception e) {
            return error();
        }

        //----------3，整理resultData数据，返回给app（此处不需要返回data，只返回code和msg即可）----------
        resultData.setCode(10000);
        resultData.setMsg("蜜罐报告查询存储，请求成功！");
        return success(resultData);

    }

}
